;
(function () {
  let oImgs = document.getElementsByClassName('list-img')

  var init = function () {
    bindEvent()
    console.log(1);
    setTimeout(() => {
      window.scrollTo(0, 0)
    }, 100)
  }

  var bindEvent = function () {
    window.onload = window.onscroll = throttle(imgLazyLoad(oImgs), 500)

  }

  function imgLazyLoad(images) {
    var imgItem = null;
    let cHeight = window.innerHeight || document.documentElement.clientHeight

    return function () {
      // console.log(1);

      var sTop = document.documentElement.scrollTop || document.body.scrollTop

      for (let i = 0; i < oImgs.length; i++) {
        imgItem = oImgs[i]
        if (imgItem.offsetTop < cHeight + sTop) {
          imgItem.src = imgItem.getAttribute('data-src')
        }
      }
    }
  }

  init();

})()

function throttle(fn, delay) {
  var t = null,
    res,
    begin = new Date().getTime()

  return function () {
    var args = arguments,
      _self = this,
      cur = new Date().getTime();

    if (t) {
      clearTimeout(t)
    }

    if (cur - begin >= delay) {
      res = fn.apply(_self, args)
      begin = cur
    } else {
      t = setTimeout(function () {
        res = fn.apply(_self, args)
      }, delay)
    }
    return res;
  };
}